package com.lx.druid;

import java.sql.Connection;

import java.sql.PreparedStatement;
import java.sql.SQLException;

/**
 * 使用新的工具类
 */
public class DruidDemo2 {
    public static void main(String[] args) throws SQLException {
        /*
         *完成添加操作
         */
        Connection conn = null;
        PreparedStatement pstm = null;

        try {
            //1. 获取连接
            conn = Demo2.getConnection();
            //2. 定义sql
            String sql = "insert into student1 (id,name) values(default,?)";
            //3. 获取pstm对象
            pstm = conn.prepareStatement(sql);
            //4. 赋值
            pstm.setString(1, "zhangshan");
            //5. 执行sql
            int i = pstm.executeUpdate();
            System.out.println(i);
        } catch (SQLException e) {
            e.printStackTrace();
        } finally {
            //6. 释放资源
            Demo2.close(pstm, conn);
        }
    }
}
